package com.yaorange.teaching.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import com.yaorange.teaching.domain.YaCourseDesign;
import com.yaorange.teaching.domain.YaCourseDesignDetail;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.yaorange.common.log.annotation.Log;
import com.yaorange.common.log.enums.BusinessType;
import com.yaorange.common.security.annotation.RequiresPermissions;
import com.yaorange.teaching.domain.YaCourse;
import com.yaorange.teaching.service.IYaCourseService;
import com.yaorange.common.core.web.controller.BaseController;
import com.yaorange.common.core.web.domain.AjaxResult;
import com.yaorange.common.core.utils.poi.ExcelUtil;
import com.yaorange.common.core.web.page.TableDataInfo;

/**
 * 课程Controller
 *
 * @author ruoyi
 * @date 2024-11-30
 */
@RestController
@RequestMapping("/course")
public class YaCourseController extends BaseController
{
    @Autowired
    private IYaCourseService yaCourseService;


    /**
     * 查询课程列表
     */
    @RequiresPermissions("teaching:course:list")
    @GetMapping("/list")
    public TableDataInfo list(YaCourse yaCourse)
    {
        startPage();
        List<YaCourse> list = yaCourseService.selectYaCourseList(yaCourse);
        return getDataTable(list);
    }


    /**
     * 查询课程列表
     */
    @RequiresPermissions("teaching:course:list")
    @GetMapping("/list/all")
    public TableDataInfo listall(YaCourse yaCourse)
    {
        List<YaCourse> list = yaCourseService.selectYaCourseList(yaCourse);
        return getDataTable(list);
    }

    /**
     * 导出课程列表
     */
    @RequiresPermissions("teaching:course:export")
    @Log(title = "课程", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, YaCourse yaCourse)
    {
        List<YaCourse> list = yaCourseService.selectYaCourseList(yaCourse);
        ExcelUtil<YaCourse> util = new ExcelUtil<YaCourse>(YaCourse.class);
        util.exportExcel(response, list, "课程数据");
    }

    /**
     * 获取课程详细信息
     */
    @RequiresPermissions("teaching:course:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(yaCourseService.selectYaCourseById(id));
    }

    /**
     * 新增课程
     */
    @RequiresPermissions("teaching:course:add")
    @Log(title = "课程", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody YaCourse yaCourse)
    {
        return toAjax(yaCourseService.insertYaCourse(yaCourse));
    }

    /**
     * 新增课程设计
     */
    @RequiresPermissions("teaching:course:add")
    @Log(title = "课程", businessType = BusinessType.INSERT)
    @PutMapping("/design")
    public AjaxResult design(@RequestParam("stage")Integer stage,@RequestParam("courseId")Long courseId, @RequestBody List<YaCourseDesignDetail> courseDesignDetailList)
    {
        return toAjax(yaCourseService.insertYaCourseDesignDetail(stage,courseId,courseDesignDetailList));
    }

    /**
     * 修改课程
     */
    @RequiresPermissions("teaching:course:edit")
    @Log(title = "课程", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody YaCourse yaCourse)
    {
        return toAjax(yaCourseService.updateYaCourse(yaCourse));
    }

    /**
     * 删除课程
     */
    @RequiresPermissions("teaching:course:remove")
    @Log(title = "课程", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(yaCourseService.deleteYaCourseByIds(ids));
    }
}
